home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7882 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Date question
  5. Date: Thu, 29 Feb 1996 16:50:42 +0200
  6. Organization: Carelcomp Forest
  7. Message-ID: <3135BD42.236B@cmt.lpr.mail.carel.fi>
  8. References: <4h3kpb$i3s@news.ysu.edu>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Jerry Tomko wrote:
  16. > Hello.   Does anyone know where I can find a program that,
  17. > when given the month, day, and year, will determine the
  18. > corrosponding day of the week (Sunday, Monday, Tuesday, etc..)?
  19. > Jerry.
  20.  
  21. If you use C, you can try:
  22.  
  23.     #include    <time.h>
  24.     #include    <string.h>
  25.  
  26.     int    GetDayOfWeek(int y, int m, int d)
  27.     {
  28.         struct tm    t;
  29.  
  30.         memset(&t, 0, sizeof(t));
  31.         t.tm_year = y - 1900;
  32.         t.tm_mon = m - 1;
  33.         t.tm_mday = d;
  34.         if ((int)mktime(&t) == -1)
  35.             return -1;    /* Error: invalid date */
  36.         return t.tm_wday;    /* 0 = sunday, 1 = monday etc */
  37.     }
  38.  
  39. Later,
  40.  AriL
  41. -- 
  42. All my opinions are mine and mine alone.
  43.